/**
 * 初始化社区示例数据
 * 在应用启动时调用此函数，可以为localStorage添加一些示例帖子
 */
export const initializeSocialData = () => {
  // 检查是否已有帖子数据
  const existingData = localStorage.getItem('socialPosts')
  if (!existingData) {
    // 创建示例帖子数据
    const samplePosts = [
      {
        id: '1001',
        author: '时尚达人',
        content: '今天分享一下我最近入手的夏季新款连衣裙，真的太适合夏天了！面料舒适，设计也很独特，强烈推荐给大家～ #夏季穿搭 #时尚分享',
        images: [
          'https://picsum.photos/id/64/800/1000',
          'https://picsum.photos/id/26/800/1000'
        ],
        video: null,
        createdAt: new Date(Date.now() - 2 * 60 * 60 * 1000).toISOString(), // 2小时前
        likes: [
          { username: 'user1', createdAt: new Date().toISOString() },
          { username: 'user2', createdAt: new Date().toISOString() }
        ],
        comments: [
          {
            id: '2001',
            author: '小美',
            content: '这件连衣裙真的好好看！请问是什么牌子的呀？',
            createdAt: new Date(Date.now() - 1 * 60 * 60 * 1000).toISOString(),
            replyTo: null
          },
          {
            id: '2002',
            author: '时尚达人',
            content: '是ZARA的新款，价格也很亲民哦～',
            createdAt: new Date(Date.now() - 30 * 60 * 1000).toISOString(),
            replyTo: {
              id: '2001',
              author: '小美'
            }
          }
        ]
      },
      {
        id: '1002',
        author: '美食博主',
        content: '自制芒果千层蛋糕，简单又好吃！周末在家试试吧～\n\n材料：\n- 芒果2个\n- 奶油200ml\n- 鸡蛋3个\n- 面粉100g\n\n步骤放在评论区了～',
        images: [
          'https://picsum.photos/id/431/800/800'
        ],
        video: null,
        createdAt: new Date(Date.now() - 5 * 60 * 60 * 1000).toISOString(), // 5小时前
        likes: [
          { username: 'user3', createdAt: new Date().toISOString() },
          { username: 'user4', createdAt: new Date().toISOString() },
          { username: 'user5', createdAt: new Date().toISOString() }
        ],
        comments: [
          {
            id: '2003',
            author: '吃货小王',
            content: '看起来太美味了！我周末一定要试试～',
            createdAt: new Date(Date.now() - 4 * 60 * 60 * 1000).toISOString(),
            replyTo: null
          }
        ]
      },
      {
        id: '1003',
        author: '旅行爱好者',
        content: '分享一段在海边的日出视频，真的太美了！希望大家都能看到这么美的景色～ #旅行 #日出 #海边',
        images: [],
        video: 'https://samplelib.com/lib/preview/mp4/sample-15s.mp4', // 示例视频URL
        createdAt: new Date(Date.now() - 24 * 60 * 60 * 1000).toISOString(), // 1天前
        likes: [
          { username: 'user6', createdAt: new Date().toISOString() },
          { username: 'user7', createdAt: new Date().toISOString() },
          { username: 'user8', createdAt: new Date().toISOString() },
          { username: 'user9', createdAt: new Date().toISOString() }
        ],
        comments: [
          {
            id: '2004',
            author: '摄影师小李',
            content: '画面太美了！请问是在哪里拍摄的？',
            createdAt: new Date(Date.now() - 20 * 60 * 60 * 1000).toISOString(),
            replyTo: null
          },
          {
            id: '2005',
            author: '旅行爱好者',
            content: '在三亚的亚龙湾，早上5点起床去拍的，真的很值得！',
            createdAt: new Date(Date.now() - 18 * 60 * 60 * 1000).toISOString(),
            replyTo: {
              id: '2004',
              author: '摄影师小李'
            }
          }
        ]
      }
    ]
    
    // 保存到localStorage
    localStorage.setItem('socialPosts', JSON.stringify(samplePosts))
    console.log('社区示例数据已初始化')
  }
}

/**
 * 清除社区数据（用于测试）
 */
export const clearSocialData = () => {
  localStorage.removeItem('socialPosts')
  console.log('社区数据已清除')
}